/*
 * @(#)EmailMessageImpl.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */

package com.dcivision.mail.bean;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.dcivision.dms.bean.EmailMessageToRule;
import com.dcivision.framework.bean.AbstractBaseObject;

/**
 * EmailMessageImpl.java
 * 
 * Implementation class of a EmailMessage
 * 
 * @author Holmes Yan
 * @company DCIVision Limited
 * @creation 18/07/2004
 * @version $Revision: 1.12 $
 * @see EmailMessage
 */
public class EmailMessageImpl extends AbstractBaseObject implements EmailMessage {

  public static final String REVISION = "$Revision: 1.12 $";
  static final long serialVersionUID = 6845202943820835477L;

  private String subject;
  private String oriSubject;
  private String sender;
  private Date sendDate;
  private String to;
  private String cc;

  private int size;
  // if the content is html and have "cid:xxx",this "cid:xxx" will be replaced to "emailArchiveGetImage?xxxx"
  private Object content;
  //original email content
  private String oriContent;
  private int priority;
  private boolean isTextOnly;
  private boolean haveAttachment;
  private boolean isHtml;
  private boolean isSaved;
  private List attachments = new ArrayList();
  private String messageID;
  private boolean analyzed = false;
  private String emailContentType;

  public static EmailMessageImpl newInstance() {
    return new EmailMessageImpl();
  }

  private EmailMessageImpl() {
  }

  public String getSubject() {
    return subject;
  }

  public void setSubject(String subject) {
    this.subject = subject;
  }

  public String getOriSubject() {
    return oriSubject;
  }

  public void setOriSubject(String oriSubject) {
    this.oriSubject = oriSubject;
  }


  public String getSender() {
    return sender;
  }

  public void setSender(String sender) {
    this.sender = sender;
  }
  public Date getSendDate() {
    return sendDate;
  }

  public void setSendDate(Date sendDate) {
    this.sendDate = sendDate;
  }

  public String getCc() {
    return cc;
  }

  public void setCc(String cc) {
    this.cc = cc;
  }

  public String getTo() {
    return to;
  }

  public void setTo(String to) {
    this.to = to;
  }

  public int getSize() {
    return size;
  }

  public void setSize(int size) {
    this.size = size;
  }

  public Object getContent() {
    return content;
  }

  public void setContent(Object content) {
    this.content = content;
  }
  public String getOriContent() {
    return oriContent;
  }

  public void setOriContent(String oriContent) {
    this.oriContent = oriContent;
  }

  public int getPriority() {
    return priority;
  }

  public void setPriority(int priority) {
    this.priority = priority;
  }

  public boolean isTextOnly() {
    return isTextOnly;
  }

  public void setIsTextOnly(boolean isTextOnly) {
    this.isTextOnly = isTextOnly;
  }

  public boolean getHaveAttachment() {
    return haveAttachment;
  }

  public void setHaveAttachment(boolean haveAttachment) {
    this.haveAttachment = haveAttachment;
  }

  public boolean isHtml() {
    return isHtml;
  }

  public void setIsHtml(boolean isHtml) {
    this.isHtml = isHtml;
  }

  public List getAttachments() {
    return attachments;
  }

  public void addAttachment(EmailAttachmentImpl emailAttachement) {
    attachments.add(emailAttachement);
  }

  public EmailAttachment getAttachment(int id) {
    return (EmailAttachment) attachments.get(id);
  }

  public boolean getIsSaved() {
    return isSaved;
  }

  public void setIsSaved(boolean isSaved) {
    this.isSaved = isSaved;
  }

/*  
  public String getSortValue(String SortName) {
    if (SortName == null) {
        return getID();
    }
    SortName = SortName.trim();
    if ("SUBJECT".equals(SortName)) {
        return getSubject();
    } else if ("SENDER".equals(SortName)) {
        return getSender();
    } else if ("SEND_DATE".equals(SortName)) {
        //String pattern = TextUtility.getDateTimeFormat().toPattern();
        //return TextUtility.formatDate(getSendDate().get, pattern);
        return getSendDate();
    } else if ("SIZE".equals(SortName)) {
        return new Integer(getSize());
    } else if ("PRIORITY".equals(SortName)) {
        return new Integer(getPriority());
    } else {
        return getID();
    }
  }
*/
  
  public String getMessageID() {
    return messageID;
  }

  public void setMessageID(String messageID) {
    this.messageID = messageID;
  }

  public boolean getAnalyzed() {
    return analyzed;
  }

  public void setAnalyzed(boolean analyzed) {
    this.analyzed = analyzed;
  }

  public String getEmailContentType() {
    return emailContentType;
  }

  public void setEmailContentType(String emailContentType) {
    this.emailContentType = emailContentType;
  }

  public void addAttachment(EmailAttachment emailAttachement){
    attachments.add(emailAttachement);
  }

  public void setEmailMessageData(EmailMessageToRule emailMessageToRule) {
    this.subject = emailMessageToRule.getSubject();
    this.sender = emailMessageToRule.getSender();
  this.oriSubject = emailMessageToRule.getOriSubject();
    this.sendDate =  emailMessageToRule.getSendDate();
    this.to = emailMessageToRule.getTo();
    this.cc = emailMessageToRule.getCc();

    this.size = emailMessageToRule.getSize();
    this.content = emailMessageToRule.getContent();
    this.oriContent = emailMessageToRule.getOriContent();
    this.priority = emailMessageToRule.getPriority();

    this.isTextOnly = emailMessageToRule.isTextOnly();
    this.isSaved = emailMessageToRule.getIsSaved();
    this.attachments = emailMessageToRule.getAttachments();
    this.messageID = emailMessageToRule.getMessageID();
    this.analyzed = emailMessageToRule.getAnalyzed();
    this.haveAttachment = emailMessageToRule.getHaveAttachment() ;
    this.isHtml = emailMessageToRule.isHtml();
  }

}